package com.lsk.serviceDriverUser.service;

import com.lsk.internalcommon.DTO.DriverUserWorkStatus;
import com.lsk.internalcommon.DTO.ResponseResult;
import com.lsk.serviceDriverUser.mapper.DriverUserWorkStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DriverUserWorkStatusService {
    @Autowired
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;

    public ResponseResult changeWorkStatus(Long driverId,Integer workStatus){
        Map<String,Object> map = new HashMap<>();
        map.put("driver_id",driverId);
        List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectByMap(map);
        if (driverUserWorkStatuses.size()==0){
            return ResponseResult.fail("没有司机");
        }
        DriverUserWorkStatus driverUserWorkStatus = driverUserWorkStatuses.get(0);
        LocalDateTime now = LocalDateTime.now();
        driverUserWorkStatus.setGmtCreate(now);
        driverUserWorkStatus.setGmtModified(now);
        driverUserWorkStatus.setWorkStatus(workStatus);
        driverUserWorkStatusMapper.updateById(driverUserWorkStatus);
        return ResponseResult.success("修改司机工作状态成功");
    }
}
